#{extends 'overlay.html' /}
#{set title:'Request deletion from :'+project.name /}

<h2>Deletion request page</h2>

<b>Are you sure you want to remove yourself from Project (${project.name})</b>
<br>
<b>All the roles you have in this project will be revoked. However, your work will still be visible by all the project members</b>
<br>
#{if connected.in(project).can('manageRequests')}
#{note} Since you have the permission of managing the Project Requests, therefore your deletion request will be approved directly and you will be deleted from the project#{/note}
#{/if}

<br><br>

<input type="checkbox" onClick="delete_checked()"/> I confirm I want to delete myself from the Project<br>

<input type="button" id="d_b"onclick="delete_proj(${project.id},${connected.in(project).can('manageRoles') ? true : false})" value="Request deletion" style="display : none"/>

<script type="text/javascript">

function delete_proj(id,hasRole)
{
	$.post('/Projects/RequestDeletedFromProject',{id:id},function(flag)
			{
				if(flag)
				{
					if(hasRole)
					{
					window.parent.$('#getOverlay').hide();
					window.parent.$.bar({ message:'You have deleted yourself from the Project.' });
					window.parent.$('#project-button-'+id).fadeOut(function() {
						$(this).remove()
					})
					window.parent.$('.workspace-'+id).remove()
					
						window.parent.$('#workspaces').hide()
						window.parent.$('#normal').show()
						window.parent.$('.project-button').removeClass('selectedADiv')
					}
					else
					{
						window.parent.$('#getOverlay').hide();
						window.parent.$.bar({ message:'A request has been sent and you will be notified upon approval.' });
					}
				}
				else
				{
					window.parent.$('#getOverlay').hide();
					$.bar({ message:'You have already requested to be deleted from the project, Please wait for the approval.' });
				}				
			}
			
	);
}

function delete_checked()
{
	$('#d_b').toggle();
}

</script>